const { defineConfig } = require("@vue/cli-service");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = defineConfig({
  transpileDependencies: true,
  //scss配置全局变量
  css: {
    /*
    cass-locader的版本不同，additionalData也会不同，
      sass-loader:v10以上就用：additionalData
      sass-loader:v8以上就用：prependData
      sass-loader:v8-以下就用：data
    */
    loaderOptions: {
      sass: {
        additionalData: `@import "@/styles/variable.scss";`,
      },
    },
  },
  //代码混淆
  configureWebpack: (config) => {
    if (process.env.NODE_ENV == "production") {
      // 为生产环境修改配置
      config.mode = "production";
      // 将每个依赖包打包成单独的js文件
      let optimization = {
        minimize: true,
        minimizer: [
          new TerserPlugin({
            terserOptions: {
              warnings: false,
              compress: {
                drop_console: true,
                drop_debugger: false,
                pure_funcs: ["console.log"],
              },
            },
          }),
        ],
      };
      Object.assign(config, {
        optimization,
      });
    } else {
      // 为开发环境修改配置
      config.mode = "development";
    }
  },
});
